import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
//elementUi的自动导入
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
//elementIcons的自动导入
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver(), IconsResolver({
        prefix: 'Icon'
      }),],
    }),
    Icons({
      autoInstall: true,
    }),
    Components({
      resolvers: [ElementPlusResolver(), IconsResolver({
        enabledCollections: ['ep']
      })],
    }),
  ],
  server: {
    // port:5000,
    cors: true,
    // 自动打开
    open: true,
    proxy: { // 配置跨域
      '/apis': {
        // target: 'http://my.mcdd.top:9527/',
        target: 'http://localhost:8085/', // 根据需求替换 请求后台接口
        changeOrigin: true, // 允许跨域
        ws: true,
        rewrite: (path) => path.replace(/^\/apis/, '') // 重写请求
      }
    }
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})
